
#region Imported Namespaces
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Text;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;

using PHSRAG.Utility;
using PHSRAG.Insight21.SearchContext;
using PlaceHolderEx = PHSRAG.WebControls.PlaceHolderEx;
using Calendar = PHSRAG.WebControls.Calendar;
using DataAccess = PHSRAG.Utility.DataAccess;
using SessionCachePolicy = PHSRAG.Insight21.Policy.SessionCachePolicy;
using Policy = PHSRAG.Insight21.Policy;
#endregion

namespace PHSRAG.Insight21.InsightWebControls
{
	#region Class AgreementSubSearch
	/// <summary>
	/// The AgreementSubSearch control is used by Agreement summary pages.
	/// </summary>
	[ToolboxData("<{0}:AgreementSubSearch runat=server />"), Designer(typeof(AgreementSubSearchDesigner))]
	public class AgreementSubSearch : System.Web.UI.WebControls.WebControl, INamingContainer
	{
		#region Constants
		private const string SubSearchControlKey = "subSearchControl_D0EFC9DF-B774-42e3-98A5-43B5C6896082";
		#endregion

		#region Instance Variables
		/// <summary>
		/// The place holder maintains viewstate and holds a page specific search control.
		/// </summary>
		private PlaceHolder placeHolderEx;
		#endregion

		#region Public Properties
		/// <summary>
		/// Get/Set the control which provides search capabilities.
		/// </summary>
		public string SubSearchControl
		{
			get { return ViewState[SubSearchControlKey] as string; }
			set { ViewState[SubSearchControlKey] = value; }
		}
		#endregion
		
		#region Virtual Methods
		/// <summary>
		/// Invoked by the method which builds the HTML representation of the control tree. Derived classes would typically
		/// return the HTML to be inserted into the stream AFTER the indicated row.
		/// </summary>
		/// <param name="currentRowNumber">The number (starting from 1) of the row that the HTML returned by this method
		/// would be inserted at.
		/// </param>
		/// <returns>HTML string to add at row number currentRowNumber</returns>
		protected virtual string GetHTML(int currentRowNumber)
		{
			return string.Empty;
		}
		#endregion

		#region Overrides
		/// <summary>
		/// Create all controls. Notice that the creation is more than just instantiating the controls. It also involves
		/// in generating the underlying HTML so that the controls shows up per the need.
		/// </summary>
		protected override void CreateChildControls()
		{
			CreateControls();
			GenerateControlTree();
		}

		/// <summary>
		/// Initialize the contents of all controls on first load. If the AgreementSubSearchContext is not cached yet, a
		/// new instance is created and cached.
		/// </summary>
		/// <param name="e">Argument associated with the event</param>
		protected override void OnLoad(EventArgs e)
		{
			if (!Page.IsPostBack)
				EnsureChildControls();
		}
		#endregion

		#region Private Methods
		/// <summary>
		/// Create all controls in the CommonSearch.
		/// </summary>
		private void CreateControls()
		{
			placeHolderEx = new PlaceHolder();
			placeHolderEx.ID = "placeHolderEx";	
			Control subSearchControl = Page.LoadControl(SubSearchControl);
			subSearchControl.ID = "SubSearchControl";
			placeHolderEx.Controls.Add(subSearchControl);
		}

		/// <summary>
		/// Setup the control tree to reflect the actual (and exact) layout of the controls within the CommonSearch.
		/// </summary>
		private void GenerateControlTree()
		{
			Table table = new Table();
			table.Width = Unit.Percentage(100);
			table.BackColor = System.Drawing.Color.White;
			Controls.Add(table);			

			TableRow row = new TableRow();
			table.Rows.Add(row);

			TableCell cell = new TableCell();
			row.Cells.Add(cell);
			cell.Controls.Add(placeHolderEx);
		}
		#endregion

		#region Internal Methods
		/// <summary>
		/// This method is ONLY invoked by the associated designer to show the control contents at design time.
		/// </summary>
		internal void Design()
		{
			EnsureChildControls();
		}
		#endregion
	}
	#endregion

	#region Class PagerDesigner
	/// <summary>
	/// Designer associated with the AgreementSubSearch control.
	/// </summary>
	/// <remarks>
	/// This class cannot be used directly.
	/// </remarks>
	public class AgreementSubSearchDesigner : ControlDesigner
	{
		#region Overrides
		/// <summary>
		/// Force the control to create its child controls for display at design time.
		/// </summary>
		/// <returns>HTML representation of the control</returns>
		public override string GetDesignTimeHtml()
		{
			((AgreementSubSearch)Component).Design();
			return base.GetDesignTimeHtml();
		}
		#endregion
	}
	#endregion
}

// --- EOF ---
